<?php
namespace Home\Controller;
use Think\Controller;
use Home\Model\UserModel;

class LoginController extends Controller {
  //登录表单处理
  public function action(){
    $data=getAjaxData(I('post.data'));
    $model=new UserModel();
    $user=$model->userVrify($data);

    $rs=[];
    if(empty($user)){
      $rs=["code"=>0,'msg'=>'用户名或密码错误'];
    }else{
      $rs=["code"=>1,"msg"=>"登陆成功"];
      session('uid',$user['id']);
      session('username',$user['name']);
    }
    $this->ajaxReturn($rs);
  }
}
